<template>
  <div class="erCode" :class="{active:isErCode}">
    <div class="erCode-bg" v-if="isErCode" @click="close"></div>
    <div class="erCode-popup" :class="{active:isErCode}">
      <span class="van-icon van-icon-cross" @click="close"></span>
      <div class="contractImg-copy">
        <div class="contractImg-box">
          <img :src="userInfo.qrcode" v-if="userInfo.qrcode" class="contractImg">
        </div>
        <span class="save" @click="saveImage()">保存图片</span>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
  name: 'ErCode',
  data () {
    return {
      ToView: false,
      contractImg: '',
      isShow: false,
      dataURLTime: null
    };
  },
  props: {
    value: {
      type: Boolean
    },
    imgUrl: {
      type: String
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
    isErCode: {
      get () {
        return this.value;
      },
      set (value) {
        this.$emit('input', value);
      }
    }
  },
  methods: {
    saveImage () {
      this.$toast('长按图片可保存到相册');
    },
    close () {
      this.isErCode = false;
    }
  }
};
</script>
<style scoped lang="less">
.erCode {
  width: 100%;
  height: 100%;
  position: fixed;
  z-index: 999;
  visibility: hidden;
}
.erCode-bg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.6);
}
.contractImg-box {
  // opacity: 1;
  position: relative;
  // top: -10000px;
}
.contractImg {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
}
.erCode-popup {
  width: 562px;
  position: absolute;
  top: 50%;
  left: 50%;
  background-color: #fff;
  vertical-align: top;
  z-index: 101;
  margin: -530px 0 0 -281px;
  transform: scale(0);
  transform-origin: 50% 50%;
  opacity: 0;
  transition: transform ease 0.3s, opacity ease 0.3s;
  .contractImg-copy {
    text-align: right;
    vertical-align: top;
    .save {
      display: inline-block;
      padding: 15px 30px;
      color: #333;
      padding-left: 40px;
      background-image: url('/static/img/icon-download.png');
      background-repeat: no-repeat;
      background-size: 30px 30px;
      background-position: left center;
      font-size: 24px;
    }
  }
  .erCodeImg {
    vertical-align: top;
  }
  .img {
    position: absolute;
    top: 359px;
    right: 48px;
    width: 162px;
    height: 162px;
  }
  .title {
    font-size: 36px;
    padding: 45px 50px 30px;
  }
  .van-icon-cross {
    color: #000;
    font-size: 30px;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    position: absolute;
    top: -18px;
    right: -16px;
    z-index: 20;
  }
}
.erCode.active {
  visibility: visible;
}
.erCode-popup.active {
  transform: scale(1);
  -webkit-transform: scale(1);
  opacity: 1;
}
</style>
